#include "demo.h"

int ordinary_search(vector_t *g, const char * ss, const char *es)//Only search for a route to the end
{
	int from_id = get_apid(ss, g);
	int to_id = get_apid(es, g);
	if(matrix2[from_id][to_id] > 0)
	{
		int k;
		if(paths[from_id][to_id][0]==0)
			printf("Traveling from %s to %s takes %d minutes \n", ss, es, matrix2[from_id][to_id]);
		else
		{
			printf("=========================\nTo go from %s to %s takes %d times and %d minutes\n",
			ss, es,
			paths[from_id][to_id][0], 
			matrix2[from_id][to_id]);

			printf("Transfer scheme is as follows:\n-------------------------\n");
			printf("\t%d: %s", 1, get_apname(from_id, g));
			printf(" --> %s\t%d minutes\n", get_apname(paths[from_id][to_id][1], g), matrix[from_id][paths[from_id][to_id][1]]);
			for(k=1; k<=paths[from_id][to_id][0]; ++k)
			{
				int ap1, ap2;
				ap1 = paths[from_id][to_id][k];
				ap2 = k < paths[from_id][to_id][0] ? paths[from_id][to_id][k+1] : to_id;
				//printf("\t%d: %s --> %s\t%d minutes\n", k+1,get_apname(ap1, g), get_apname(ap2, g), matrix[ap1][ap2]);
				printf("\t%d: %s", k+1, get_apname(ap1, g));
				printf(" --> %s\t%d minutes\n", get_apname(ap2, g), matrix[ap1][ap2]);
			}
		} 
	}
	else
		printf("There is no flight or transfer plan from %s to %s\n", ss, es);

	return 1;
/*	int bus_route = 0;
	iterator_t iv, ie, bus;
	struct vertex v;
	struct edge e, br;
	for(iv = vector_begin(g); !iterator_equal(iv, vector_end(g)); iv = iterator_next(iv))
	{
		iterator_get_value(iv, &v);
		if(strcmp(ss, v.vlabel) == 0)
		{
			for(ie = vector_begin(v.edges); !iterator_equal(ie, vector_end(v.edges)); ie = iterator_next(ie))
			{
				iterator_get_value(ie, &e);
				printf("%s\n", e.elabel);
				if(strcmp(es, e.elabel) == 0)
				{
					printf("%s", v.vid);
					for (bus = vector_begin(v.edges); !iterator_equal(bus, ie); bus = iterator_next(bus))
					{
						bus_route++;
						iterator_get_value(bus, &br);
						printf("-->%s", br.eid);
					}
					printf("-->%s", e.eid);
					printf("\n");
				}
			}	
		}
	}
	if (bus_route == 0)
	{
		printf("Sorry, Didn't find the feiji information.\n");
	}*/
}
